package com.yb;

/**
 * 递归解法题
 */
public class RecursionWorks {

    /**
     * 字符串反转
     * @param s
     * @return
     */
    public static String revert(String s) {
        if (s == null || s.length() <= 1) {
            return s;
        }
        return s.charAt(s.length() - 1) + revert(s.substring(0, s.length() - 1));
    }

    /**
     * 汽水瓶问题
     *
     * @param n
     * @return
     */
    public static int solution(int n) {
        if (n == 1) {
            return 0;
        }
        if (n == 2) {
            return 1;
        }
        return n / 3 + solution(n / 3 + n % 3);
    }
}
